package com.piggy.logi.sys.controller;

import com.google.common.collect.Lists;
import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.annotation.Inner;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.api.bo.LogiPricePlanExtEditBo;
import com.piggy.logi.sys.api.bo.LogiPricePlanQueryBo;
import com.piggy.logi.sys.api.vo.LogiPricePlanExtVo;
import com.piggy.logi.sys.service.ILogiPricePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * 价格方案管理Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "价格方案管理控制器", tags = {"价格方案管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/logi/sys/plan")
public class InnerLogiPricePlanController extends BaseController {

    private final ILogiPricePlanService iLogiPricePlanService;

    /**
     * 查询价格方案管理列表
     */
    @Inner
    //@SaCheckPermission("sys:plan:list")
    @PostMapping("/inner/list")
    public TableDataInfo<LogiPricePlanExtVo> innerList(@Validated @RequestBody LogiPricePlanQueryBo bo) {
        bo.setDeptId(0L);
        bo.setProjectId(0L).setProjectShiplineId(0L);
        return iLogiPricePlanService.queryPageList(bo);
    }

    /**
     * 查询价格方案管理列表
     */
    @Inner
    //@SaCheckPermission("sys:plan:list")
    @PostMapping("/inner/queryList")
    public R<List<LogiPricePlanExtVo>> queryInnerList(@Validated @RequestBody LogiPricePlanQueryBo bo) {
        bo.setDeptId(0L);
        bo.setProjectId(0L).setProjectShiplineId(0L);
        return R.ok(iLogiPricePlanService.queryList(bo));
    }

    /**
     * 获取价格方案管理详细信息
     */
    @Inner
    //@SaCheckPermission("sys:plan:query")
    @GetMapping("/inner/{id}")
    public R<LogiPricePlanExtVo> innerInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable("id") Long id) {
        return R.ok(iLogiPricePlanService.queryById(id));
    }

    /**
     * 新增价格方案管理
     */
    @Inner
    //@SaCheckPermission("sys:plan:add")
    @PostMapping("/inner/add")
    public R<LogiPricePlanExtVo> innerAdd(@Validated @RequestBody LogiPricePlanExtEditBo bo) {
        bo.setDeptId(0L);
        return R.ok(iLogiPricePlanService.insertByAddBo(bo));
    }

    /**
     * 修改价格方案管理
     */
    @Inner
    //@SaCheckPermission("sys:plan:edit")
    @PostMapping("/inner/edit")
    public R<LogiPricePlanExtVo> innerEdit(@Validated @RequestBody LogiPricePlanExtEditBo bo) {
        bo.setDeptId(0L);
        return R.ok(iLogiPricePlanService.updateByEditBo(bo));
    }

    /**
     * 删除价格方案管理
     */
    @Inner
    //@SaCheckPermission("sys:plan:remove")
    @PostMapping("/inner/remove/{ids}")
    public R<Integer> innerRemove(@NotEmpty(message = "主键不能为空")
                             @PathVariable(value = "ids") Long[] ids) {
        return R.ok(iLogiPricePlanService.deleteWithValidByIds(Lists.newArrayList(ids), true) ? 1 : 0);
    }

}
